package com.javabase.Object.ObjectMiddle.Work;

public class Work10 {
    public static void main(String[] args) {
        //编写Doctor类 属性:name,age,job,gender,sal/
        //重写父类(Object)的equals()方法:public bollean equals(Object obj),
        //并判断测试类中创建的两个对象是否相等。【相等就是判断属性是否相同】
        Doctor doctor = new Doctor("feng", 18, "无业", "男", 0);
        Doctor doctor1 = new Doctor("feng", 18, "无业", "男", 0);
        System.out.println(doctor.equals(doctor1));//T

    }
}

class Doctor {
    private String name;
    private int age;
    private String job;
    private String gender;
    private double sal;

    public Doctor(String name, int age, String job, String gender, double sal) {
        this.name = name;
        this.age = age;
        this.job = job;
        this.gender = gender;
        this.sal = sal;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {//判断两个对象是否相等
            return true;
        }
        //过关斩将

        if (!(obj instanceof Doctor)) { //判断obj是否是Doctor类或其子类
            return false;
        }
        Doctor doctor = (Doctor) obj;//向下转型 obj【父类引用】  doctor(子类引用)
        //向下转型后就可以访问子类的属性了

        return this.name.equals(doctor.name) && this.age == doctor.age && this.job.equals(doctor.job) && this.gender.equals(doctor.gender) && this.sal == doctor.sal;
    }
}